package com.liner;

import java.util.Scanner;

public class Guessing {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        /*Random random = new Random();
        int num = random.nextInt(1000);
        */



        int num = (int) (Math.random() * 1000) + 1;
        int count = 10;
 /*
        System.out.print("猜个数字试试吧(你只有10次机会):");
        int guess = scanner.nextInt();
        while (true) {
            if (guess > num) {
                System.out.println("猜大了");
            } else if (guess < num) {
                System.out.println("猜小了");
            }else {
                System.out.println("恭喜你猜对了");
                break;
            }
            System.out.println("当前剩余次数:" + --count);
            if (count == 0) {
                System.out.println("机会用光了");
                break;
            }
            System.out.print("再猜个数字试试吧:");
            guess = scanner.nextInt();

        }
        System.out.println("本次所用次数:" + (10-count));

*/


        int guess;
        do {
            System.out.print("猜个数字试试吧(你只有10次机会):");
            guess = scanner.nextInt();
            if (guess > num) {
                System.out.println("猜大了");
                System.out.println("当前剩余次数:" + --count);
            } else if (guess < num) {
                System.out.println("猜小了");
                System.out.println("当前剩余次数:" + --count);
            } else {
                System.out.println("恭喜你猜对了");
                System.out.println("你所用次数是:" + (10-count));
            }
            if (count == 0) {
                System.out.println("对不起，次数用尽");
                break;
            }
        } while (guess != num);



    }
}
